package com.wangshouyu.plugins.mvc.response;

import java.io.Serializable;

/**
 * @author 王守钰
 * @date 2020年11月20日 13:38
 * @description 包装返回结果
 */
public class DefaultResponseResult<T> implements Serializable {

    /**
     * 响应数据
     */
    private T data;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应码
     */
    private Integer code;

    /**
     * 成功状态码
     */
    public static final Integer SUCCESS_CODE = 200;

    /**
     * 成功消息
     */
    public static final String SUCCESS_MESSAGE = "success";

    /**
     * 失败状态码
     */
    public static final Integer FAIL_CODE = 500;

    /**
     * 失败消息
     */
    public static final String FAIL_MESSAGE = "fail";

    public DefaultResponseResult(T data, String message, Integer code) {
        this.data = data;
        this.message = message;
        this.code = code;
    }

    public DefaultResponseResult() {
    }

    public static <T> DefaultResponseResult<T> success(T data) {
        return new DefaultResponseResult<T>(data, SUCCESS_MESSAGE, SUCCESS_CODE);
    }

    public static <T> DefaultResponseResult<T> fail(T data) {
        return new DefaultResponseResult<T>(data, FAIL_MESSAGE, FAIL_CODE);
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
